//
//  LSZImageViewFocusOnTableViewCell.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/14.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZImageViewFocusOnTableViewCell.h"
@implementation LSZImageViewFocusOnTableViewCell
-(id)initWithImageViewFocusOn :(NSArray *)array
{
    self = [super  init];
    if (self) {
        CGFloat heightA = [LSZSpecialPackaging initWithReturnsthesizeOf:60 :5];
        CGFloat wids = (ScreenWidth-10-heightA)/3;
        for (int i = 0; i<array.count; i++) {
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(heightA+ (i%3) * wids , 10+(i/3) * (wids+10), wids-10, wids-10)];
            [imageView sd_setImageWithURL:[NSURL URLWithString:array[i]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            imageView.tag = i+1;
            [imageView tapGesture:^(UIGestureRecognizer *ges) {
                self.arrayUrl = array;
                [self addImgeView:imageView.tag-1 :array];
            }];
            [self addSubview:imageView];
            if (array.count == 1) {
                imageView.frame = CGRectMake(heightA, 10,(ScreenWidth-10-heightA)/2-20, (ScreenWidth-10-heightA)/2-20);
            }
        }
    }
    return self;
}
#pragma mark - 创建有多少个
-(void)addImgeView :(NSInteger)number :(NSArray *)array
{
    // 原图的父控件
    SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
    browser.sourceImagesContainerView = self;
    // 原图的数量
    browser.imageCount = array.count;
    // 当前需要展示图片的index
    browser.currentImageIndex = number;
    // 设置代理
    browser.delegate = self;
    // 展示图片浏览器
    [browser show];
}
#pragma mark - 用来展示图片的
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
    return  [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.arrayUrl[index]]]];
}
@end
